#include<bits/stdc++.h>
using namespace std;
class Solution {
public:
    int lengthOfLongestSubsequence(vector<int>& nums, int target) {
        int m=nums.size();
        int n=target;
        vector<vector<int>> dp(m+1,vector<int>(n+1));
        for(int i=1;i<=m;i++)
        {
            for(int j=1;j<=n;j++)
            {
                dp[i][j]=dp[i-1][j];
                if((j==nums[i-1])||(j-nums[i-1]>0&&dp[i-1][j-nums[i-1]]!=0)) dp[i][j]=max(1+dp[i-1][j-nums[i-1]],dp[i][j]);
            }
        }
        return dp[m][n]==0?-1:dp[m][n];
    }
};

int main()
{
    vector<int> vec={1,1,5,4,5};
    Solution so;
    so.lengthOfLongestSubsequence(vec,3);
    return 0;
}